#ifndef MESSAGEQUEUE
#define MESSAGEQUEUE
 
#include <iostream>
#include <fcntl.h>
#include <sys/stat.h>
#include <mqueue.h>
#include <cstring>
#include <cerrno>
#include <stdexcept>
#include <mutex>
#include <map>
#include "config.h"

class MessageQueue;
extern std::map<std::string, MessageQueue*> MessageQueueList;

class MessageQueue {
public:
    MessageQueue(const std::string& name);

    MessageQueue(const std::string& name, bool open_existing);

    ~MessageQueue();

    void sendMessage(const std::string& message);
    std::string receiveMessage();

    void printAttributes();

private:
    void cleanMessage();


private:
    std::string mq_name;
    mqd_t mq;
    struct mq_attr mq_attr;
    mutable std::mutex mutex; // Ensure thread-safe access
};


#endif // MESSAGEQUEUE
